﻿#include <QCoreApplication>
#include "iostream"
//#include "GlobalMsg.h"
#include "Server_userConnect.h"

#define VERSION "0.0.1"

using namespace std;



int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    Server_userConnect* mainServer = nullptr;

    cout << R"(
     __     _       __      _               __
  /\ \ \___| |_    /__\ ___| | __ _ _   _  / _\ ___ _ ____   _____ _ __
 /  \/ / _ \ __|  / \/// _ \ |/ _` | | | | \ \ / _ \ '__\ \ / / _ \ '__|
/ /\  /  __/ |_  / _  \  __/ | (_| | |_| | _\ \  __/ |   \ V /  __/ |
\_\ \/ \___|\__| \/ \_/\___|_|\__,_|\__, | \__/\___|_|    \_/ \___|_|
                                    |___/
========================================================================
)";
    cout << endl;
    while(true){
        cout << "\nconsole:";
        string t_cin;
        cin >> t_cin;
        transform(t_cin.begin(),t_cin.end(),t_cin.begin(),::tolower);

        if(t_cin == "-h" || t_cin == "-help"){ //判断是否为帮助
            cout << "Commands:" << endl
                 << "-help          get help information" << endl
                 << "-version       tool version information" <<endl
                 << "-start         start the LAN proxy service" <<endl
                 << "-stop          stop service" <<endl
                 << "-users         obtain user list" <<endl;
        }
        else if(t_cin == "-v" || t_cin == "-version"){ //判断是否为版本查询
            cout << VERSION << endl;
        }
        else if(t_cin == "-s" || t_cin == "-start"){ //开始服务
            uint16_t t_serPort = 0; //服务器端口
            while(t_serPort == 0){
                cout << "server port:";
                cin >> t_serPort;
            }

            uint32_t t_userMaxNumber = 0; //服务器端口
            while(t_userMaxNumber < 1){
                cout << "maximum number of users:";
                cin >> t_userMaxNumber;
            }

            mainServer = new Server_userConnect(t_serPort,t_userMaxNumber);
            if(mainServer->isValid()){
                cout << "Success!" << endl;
                break;
            }
            else{
                cout << "Error: port is occupied!" << endl;
            }


        }
    }

    cout << "log:" << endl;
    return a.exec();

}
